package com.suixinsanren.design.state.demo.demo02;

public class SoldState implements State {

    private GumballMachine gumballMachine;

    public SoldState(GumballMachine gumballMachine) {
        this.gumballMachine = gumballMachine;
    }

    @Override
    public void insertQuarter() {
        System.out.println("请稍等，正在为您准备糖果");
    }

    @Override
    public void ejectQuarter() {
        System.out.println("您已经转动曲柄，无法退换硬币");
    }

    @Override
    public void turnCrank() {
        System.out.println("转两圈不会给你带来另一个糖果");
    }

    @Override
    public void dispense() {
        gumballMachine.releaseBall();
        gumballMachine.setState(gumballMachine.getCount() > 0 ?
                gumballMachine.getNoQuarterState() : gumballMachine.getSoldOutState());
    }

    @Override
    public String toString() {
        return "分发口香糖";
    }
}
